<?php

namespace App\Admin\Controllers;

use App\Models\Business;
use App\Models\CollPosition;
use App\Models\ExpressCompany;
use App\Models\PersonalUser;
use App\Models\Product;
use App\Models\ProductAttrKey;
use App\Models\Resume;
use Encore\Admin\Controllers\AdminController;
use App\Admin\Actions\Post\Restore;
use App\Admin\Actions\Post\productSKUList;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;


class BusinessController extends AdminController
{
    protected $title = '商家列表';
    protected $status_arr = ['-1' => '已拒绝', '0' => '待审核', '1' => '正常'];
    protected $oper_status_arr = ['-1' => '拒绝', '1' => '同意'];

    protected function grid()
    {
        $grid = new Grid(new Business());

        $grid->column('id', __('Id号'));
        $grid->column('name', __('名称'));
        $grid->column('owner', __('店主姓名'));
        $grid->column('mobile', __('联系方式'));
        $grid->column('cover_img', __('封面图'))->image();
        $grid->column('pics', __('图集'))->image('', 100, 100);
        $grid->column('status', __('状态'))->using($this->status_arr);
        $grid->column('updated_at', __('更新时间'));

        $grid->disableExport();
        $grid->disableRowSelector();
        $grid->disableColumnSelector();

        $grid->filter(function ($filter) {
            // 去掉默认的id过滤器
            $filter->disableIdFilter();

            // 在这里添加字段过滤器
            $filter->like('name', '名称');

        });

        $grid->actions(function ($actions) {
            // 去掉删除
            $actions->disableDelete();
        });

        return $grid;
    }

    protected function detail($id)
    {
        $show = new Show(Business::findOrFail($id));

        $show->field('name', __('名称'));
        $show->field('owner', __('店主姓名'));
        $show->field('mobile', __('联系方式'));
        $show->field('cover_img', __('封面图'))->image();
        $show->field('pics', __('图集'))->carousel();
        $show->field('introduce', __('简介'));
        $show->field('content', __('详情'))->as(function ($content) {
            return $content;
        });
        $show->field('created_at', __('创建时间'));
        $show->field('updated_at', __('更新时间'));
        $show->field('status', __('状态'))->using($this->status_arr);

        $show->panel()
            ->tools(function ($tools) {
                $tools->disableDelete();
            });;

        return $show;
    }

    protected function form()
    {
        $form = new Form(new Business());

        $form->text('name', __('名称'))->required();
        $form->text('owner', __('店主姓名'))->required();
        $form->image('cover_img', __('封面图'))->required();
        $form->multipleImage('pics', __('图集'))->required();
        $form->mobile('mobile', __('联系方式'))->required();
        $form->textarea('introduce', __('简介'))->required();
        $form->UEditor('content', '详情')->options(['initialFrameHeight' => 800]);
        $form->select('status', __('状态'))->options($this->oper_status_arr)->default(1);

        $form->tools(function (Form\Tools $tools) {
            // 去掉`删除`按钮
            $tools->disableDelete();
        });

        $form->footer(function ($footer) {
            // 去掉`继续创建`checkbox
//            $footer->disableCreatingCheck();
            // 去掉`继续编辑`checkbox
//            $footer->disableEditingCheck();
        });

        return $form;
    }
}
